package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProcessingDeliveryLetter;
import com.ruoyi.system.service.IProcessingDeliveryLetterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 加工发货函Controller
 *
 * @author ruoyi
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/system/letter")
public class ProcessingDeliveryLetterController extends BaseController {
    @Autowired
    private IProcessingDeliveryLetterService processingDeliveryLetterService;

    /**
     * 查询加工发货函列表
     */
    @PreAuthorize("@ss.hasPermi('system:letter:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcessingDeliveryLetter processingDeliveryLetter) {
        startPage();
        List<ProcessingDeliveryLetter> list = processingDeliveryLetterService.selectProcessingDeliveryLetterList(processingDeliveryLetter);
        return getDataTable(list);
    }

    /**
     * 导出加工发货函列表
     */
    @PreAuthorize("@ss.hasPermi('system:letter:export')")
    @Log(title = "加工发货函", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProcessingDeliveryLetter processingDeliveryLetter) {
        List<ProcessingDeliveryLetter> list = processingDeliveryLetterService.selectProcessingDeliveryLetterList(processingDeliveryLetter);
        ExcelUtil<ProcessingDeliveryLetter> util = new ExcelUtil<ProcessingDeliveryLetter>(ProcessingDeliveryLetter.class);
        util.exportExcel(response, list, "加工发货函数据");
    }

    /**
     * 获取加工发货函详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:letter:query')")
    @GetMapping(value = "/{keyId}")
    public AjaxResult getInfo(@PathVariable("keyId") Long keyId) {
        return success(processingDeliveryLetterService.selectProcessingDeliveryLetterByKeyId(keyId));
    }

    /**
     * 新增加工发货函
     */
    @PreAuthorize("@ss.hasPermi('system:letter:add')")
    @Log(title = "加工发货函", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProcessingDeliveryLetter processingDeliveryLetter) {
        return toAjax(processingDeliveryLetterService.insertProcessingDeliveryLetter(processingDeliveryLetter));
    }

    /**
     * 修改加工发货函
     */
    @PreAuthorize("@ss.hasPermi('system:letter:edit')")
    @Log(title = "加工发货函", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcessingDeliveryLetter processingDeliveryLetter) {
        return toAjax(processingDeliveryLetterService.updateProcessingDeliveryLetter(processingDeliveryLetter));
    }

    /**
     * 删除加工发货函
     */
    @PreAuthorize("@ss.hasPermi('system:letter:remove')")
    @Log(title = "加工发货函", businessType = BusinessType.DELETE)
    @DeleteMapping("/{keyIds}")
    public AjaxResult remove(@PathVariable Long[] keyIds) {
        return toAjax(processingDeliveryLetterService.deleteProcessingDeliveryLetterByKeyIds(keyIds));
    }
}
